
/*
 * Copyright 2002-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2021原作者。
 *
 *根据Apache许可证2.0版许可（“许可证”）；
 *除非符合许可证的规定，否则您不得使用此文件。
 *您可以在以下网址获取许可证副本：
 *
 *https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，软件
 *根据许可证进行的分发是在“按原样”的基础上进行的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限的特定语言，请参阅许可证和
 *许可证下的限制。
 */

package org.springframework.validation;

/**
 * A validator for application-specific objects.
 *
 * <p>This interface is totally divorced from any infrastructure
 * or context; that is to say it is not coupled to validating
 * only objects in the web tier, the data-access tier, or the
 * whatever-tier. As such it is amenable to being used in any layer
 * of an application, and supports the encapsulation of validation
 * logic as a first-class citizen in its own right.
 *
 * <p>Find below a simple but complete {@code Validator}
 * implementation, which validates that the various {@link String}
 * properties of a {@code UserLogin} instance are not empty
 * (that is they are not {@code null} and do not consist
 * wholly of whitespace), and that any password that is present is
 * at least {@code 'MINIMUM_PASSWORD_LENGTH'} characters in length.
 *
 * <pre class="code">public class UserLoginValidator implements Validator {
 *
 *    private static final int MINIMUM_PASSWORD_LENGTH = 6;
 *
 *    public boolean supports(Class clazz) {
 *       return UserLogin.class.isAssignableFrom(clazz);
 *    }
 *
 *    public void validate(Object target, Errors errors) {
 *       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName", "field.required");
 *       ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "field.required");
 *       UserLogin login = (UserLogin) target;
 *       if (login.getPassword() != null
 *             &amp;&amp; login.getPassword().trim().length() &lt; MINIMUM_PASSWORD_LENGTH) {
 *          errors.rejectValue("password", "field.min.length",
 *                new Object[]{Integer.valueOf(MINIMUM_PASSWORD_LENGTH)},
 *                "The password must be at least [" + MINIMUM_PASSWORD_LENGTH + "] characters in length.");
 *       }
 *    }
 * }</pre>
 *
 * <p>See also the Spring reference manual for a fuller discussion of
 * the {@code Validator} interface and its role in an enterprise
 * application.
 *
 * @author Rod Johnson
 * @see SmartValidator
 * @see Errors
 * @see ValidationUtils
 */
/**
 *应用程序特定对象的验证器。
 *
 *<p>此接口完全脱离了任何基础设施
 *或上下文；也就是说，它与验证无关
 *仅web层、数据访问层或
 *无论是哪一层。因此，它适用于任何层
 *应用程序的，并支持验证的封装
 *逻辑本身就是一等公民。
 *
 *<p>在下面找到一个简单但完整的｛@code Validator｝
 *实现，它验证各种{@linkString}
 *｛@code UserLogin｝实例的属性不为空
 *（也就是说，它们不是{@code-null}并且不包含
 *全部为空白），并且存在的任何密码
 *长度至少为{@code'MINIMUM_PASSWORD_LENGTH'}个字符。
 *
 *<pre-class=“code”>公共类UserLoginValidator实现Validator{
 *
 *private static最终int MINIMUM_PASSWORD_LENGTH=6；
 *
 *公共布尔支持（类clazz）{
 *return用户登录.class.isAssignableFrom（clazz）；
 *}
 *
 *public void validate（对象目标，错误-错误）{
 *ValidationUtils.rejectInfEmptyOrWhitespace（错误，“用户名”，“字段.必需”）；
 *ValidationUtils.rejectInfEmptyOrWhitespace（错误，“密码”，“字段.必需”）；
 *UserLogin登录=（UserLogin）目标；
 *if（login.getPassword（）！=无效的
 *&amp&amp；login.getPassword（）.trim（）.length（）&lt；最小密码长度）{
 *errors.rejectValue（“密码”，“field.min.length”，
 *new Object[]｛Integer.valueOf（MINIMUM_PASSWORD_LENGTH）｝，
 *“密码的长度必须至少为[”+MINIMUM_password_LENGTH+“]个字符。”）；
 *}
 *}
 *}</pre>
 *
 *<p>有关
 *｛@code Validator｝接口及其在企业中的角色
 *应用程序。
 *
 *@作者罗德·约翰逊
 *@请参阅SmartValidator
 *@查看错误
 *@参见验证Utils
 */
public interface Validator {

	/**
	 * Can this {@link Validator} {@link #validate(Object, Errors) validate}
	 * instances of the supplied {@code clazz}?
	 * <p>This method is <i>typically</i> implemented like so:
	 * <pre class="code">return Foo.class.isAssignableFrom(clazz);</pre>
	 * (Where {@code Foo} is the class (or superclass) of the actual
	 * object instance that is to be {@link #validate(Object, Errors) validated}.)
	 * @param clazz the {@link Class} that this {@link Validator} is
	 * being asked if it can {@link #validate(Object, Errors) validate}
	 * @return {@code true} if this {@link Validator} can indeed
	 * {@link #validate(Object, Errors) validate} instances of the
	 * supplied {@code clazz}
	 */
	/**
	 *此｛@link Validator｝｛@link#validate（Object，Errors）是否可以验证｝
	 *提供的{@code-clazz}的实例？
	 *<p>此方法<i>通常</i>是这样实现的：
	 *<pre-class=“code”>返回Foo.class.isAssignableFrom（clazz）</预>
	 *（其中｛@code Foo｝是实际的
	 *要｛@link#validate（object，Errors）验证的对象实例｝。）
	 *@param clazz此｛@link Validator｝为的｛@linkClass｝
	 *被问及是否可以｛@link#validate（Object，Errors）validate｝
	 *@return｛@code true｝如果这个｛@link Validator｝确实可以
	 *｛@link#validate（Object，Errors）validate的｝个实例
	 *提供｛@code clazz｝
	 */
	boolean supports(Class<?> clazz);

	/**
	 * Validate the supplied {@code target} object, which must be
	 * of a {@link Class} for which the {@link #supports(Class)} method
	 * typically has (or would) return {@code true}.
	 * <p>The supplied {@link Errors errors} instance can be used to report
	 * any resulting validation errors.
	 * @param target the object that is to be validated
	 * @param errors contextual state about the validation process
	 * @see ValidationUtils
	 */
	/**
	 *验证提供的｛@code target｝对象，该对象必须是
	 *｛@link#支持（Class）｝方法的｛@link Class｝的
	 *通常已（或将）返回{@code-true}。
	 *<p>提供的｛@link Errors Errors｝实例可用于报告
	 *任何由此产生的验证错误。
	 *@param target要验证的对象
	 *@param errors有关验证过程的上下文状态
	 *@参见验证Utils
	 */
	void validate(Object target, Errors errors);

}
